package concurrent.tool;

import java.util.concurrent.Semaphore;

public class SemaphoreTest {

	
	public static void main(String[] args) {
		
		final Semaphore semaphore = new Semaphore(10);
		new Thread(){
			
			@Override
			public void run() {
				
				while(semaphore.availablePermits() > 5){
					
					try {
						semaphore.acquire();
						System.out.println("倒计时：" + semaphore.availablePermits());
						Thread.sleep(1000);
//						semaphore.release();
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
		}.start();
		
		System.out.println(semaphore.availablePermits());
	}
}
